<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.awt.*,java.util.*" errorPage="" %>
<%@page import="SOAOfficeX.SOAOfficeCtrl"%>
<%@page import="com.tjsinfo.tjsoa.system.vo.User"%>
<%@page import="com.tjsinfo.tjsoa.common.ToolKit"%>

<%request.setCharacterEncoding("gb2312");%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String fawendate = request.getParameter("fawendate");
%>
<%@page pageEncoding="utf-8"%>
<%
String ServerIP = request.getServerName();

SOAOfficeX.SOAOfficeCtrl  SOACtrl = new  SOAOfficeX.SOAOfficeCtrl(pageContext);
//设置SOAOFFICE中间件服务页面
SOACtrl.ServerURL = "/soaservlet/soaserv.do";


SOACtrl.MenubarStyle = 5;
SOACtrl.MenubarColor = Color.decode("#FF6633");
SOACtrl.TitlebarColor = Color.decode("#FFFFFF");
SOACtrl.TitlebarTextColor = Color.decode("#50C048");


SOACtrl.SaveDocURL = "SaveDoc.jsp";
//取文件名称
String docname = request.getParameter("docname");
//取WorkMode
Integer workMode = Integer.parseInt(request.getParameter("WorkMode")); 
//取用户
User user = (User)session.getAttribute("user");
SOACtrl.webOpen("docs/"+docname, workMode, user.getUsername(), "Word.Document");

%>
<HTML>
<HEAD>
	<META http-equiv="Content-Type" content="text/html; charset=gb2312">
	<script type="text/javascript" src="js/control.js"></script>
	<script type="text/javascript" src="<%=basePath %>ajaxFramework/jQuery/jquery.js"></script>
</HEAD>
<BODY>
<form name="formData" method="post"  id="formData">
<!--**************   SOAOFFICE 客户端代码开始    ************************-->
	<script language="javascript">
		var isclosed = false;
		var istongguo = true;
		function savedoc()
		{
			document.all("SOAOfficeCtrl").WebSave();//保存当前文档到web服务器，保存（覆盖）到原打开文档的地址处
		}
			//插入电子印章
	function jsInsertSeal() 
		{ 
			$.ajaxSetup({
			  async: false
			  }); 
	
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.HomeKey(6);
					
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.Find.Execute(decodeURI("<%=fawendate%>"));			
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveStart();
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveRight();
						
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveLeft();
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveLeft();
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveLeft();
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveLeft();
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveLeft();
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveLeft();
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveLeft();
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveLeft();
						
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveUp();
						document.getElementById("SOAOfficeCtrl").Document.Application.Selection.MoveUp();
						
						
	
			
			if (!bDocOpen)
				alert("当前没有已打开的文档。");
			else
			{
				//document.all("SOAOfficeCtrl").InsertSealFromURL("images/seal02.esf");//不通过选择，直接插入指定印章
				var mDialogUrl = "../xingzhengfawen/selectSeal.jsp";
				
				var mObject = new Object();
				mObject.SelectValue = "";
				window.showModalDialog(mDialogUrl, mObject, "dialogHeight:180px; dialogWidth:340px;center:yes;scroll:no;status:no;"); 
				//判断用户是否选择印章
				if (mObject.SelectValue!="")
				{
					document.all("SOAOfficeCtrl").InsertSealFromURL( "../../images/" + mObject.SelectValue);
					$('#isgaizhang').attr('value',1);
				}
				
			}
		} 
		//判断是否套红和盖章
		function isgaizhang(){
			if($('#isgaizhang').attr('value') == 1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
		
</script>
	<SCRIPT language="JavaScript" event="OnInit()" for="SOAOfficeCtrl">
		// 控件打开文档前触发，用来初始化界面样式
	</SCRIPT>
	<SCRIPT language="JavaScript" event="OnDocumentOpened(str, obj)" for="SOAOfficeCtrl">
		// 控件打开文档后立即触发，添加自定义菜单，自定义工具栏，禁止打印，禁止另存，禁止保存等等
		formData.SOAOfficeCtrl.AppendToolButton(1, "盖章", 1); 
		bDocOpen = true;
	</SCRIPT>
	<SCRIPT language="JavaScript" event="OnDocumentClosed()" for="SOAOfficeCtrl">
		bDocOpen = false;
	</SCRIPT>
	<SCRIPT language="JavaScript" event="BeforeDocumentSaved(Document, Location, Cancel)" for="SOAOfficeCtrl">
		if(isclosed == false){
			isclosed = true;
			if($(parent.document.body).find("input[name=path]:checked").val() != 0){
				SOAOfficeCtrl.SaveAsReadOnly=true;
				document.getElementById("SOAOfficeCtrl").AcceptAllRevisions();
				document.getElementById("SOAOfficeCtrl").Document.Protect(2, false, "123");  //密码123，设置只读,且禁止拷贝
				SOAOfficeCtrl.WebSave();
			}
			
		}
	</SCRIPT>
	
	
	<SCRIPT language="JavaScript" event="OnUserMenuClick(index, caption)" for="SOAOfficeCtrl">
		// 添加您的自定义菜单项事件响应
	</SCRIPT>
	<SCRIPT language="JavaScript" event="OnCustomToolBarClick(index, caption)" for="SOAOfficeCtrl">
		if(index == 1) jsInsertSeal();
		// 添加您的自定义工具栏按钮事件响应
	</SCRIPT>	
	<!--   OBJECT标签，客户端控件引用    -->
	<OBJECT id="SOAOfficeCtrl" codeBase="ZSOffice.ocx#version=2,0,0,1" height="100%" width="100%" data="" classid="clsid:AD06827C-D92F-4648-B880-138AF11E8A13" VIEWASTEXT>
	<div align="center" STYLE="color:red;">
		本机尚未安装卓正OFFICE组件，请安装浏览器上方黄色提示条或弹出提示框中的卓正OFFICE组件。</div>
	</OBJECT>
<!--**************   SOAOFFICE 客户端代码结束    ************************-->
</form>
<input type="hidden" id="isgaizhang" value="0"/>
</BODY>
</HTML>